<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Make Controller Kit - Firmware API: Analog Inputs</title>
<link href="mt_doxygen.css" rel="stylesheet" type="text/css" />
<link href="../resources/mt_doxytabs.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.header {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12pt;
	color: #222222;
}
-->
</style>
</head>

<body>
<table width="800" border="0">
    <tr>
      <td colspan="3">
        <form method="get" action="http://www.google.com/search">
          <div align="right">
            <input type="text"   name="q" size="25"
              maxlength="255" value="" />
            <input type="submit" value="Search" />
            <input type="hidden" name="sitesearch" value="makingthings.com/ref/firmware/html" />
          </div>
        </form>
       </td>
    </tr>
    <tr>
      <td><div align="center"><a href="http://www.makingthings.com">
				<img src="../resources/logo_brown_medium.png" alt="MakingThings"
									width="200" height="78" border="0" align="middle" longdesc="http://www.makingthings.com" /></a></div></td>
				<td><div align="center" class="header">
      		Make Controller Kit <br />
          Firmware API
      </div></td>
      <td><div align="center"><a href="http://www.makezine.com">
					<img src="../resources/make_logo.png" alt="MAKE Zine" 
										width="164" height="73" border="0" align="middle" longdesc="http://www.makezine.com" /></a></div></td>
    </tr>
</table>
</body>
</html>
<!-- Generated by Doxygen 1.5.4 -->
<script type="text/javascript">
<!--
function changeDisplayState (e){
  var num=this.id.replace(/[^[0-9]/g,'');
  var button=this.firstChild;
  var sectionDiv=document.getElementById('dynsection'+num);
  if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){
    sectionDiv.style.display='block';
    button.src='open.gif';
  }else{
    sectionDiv.style.display='none';
    button.src='closed.gif';
  }
}
function initDynSections(){
  var divs=document.getElementsByTagName('div');
  var sectionCounter=1;
  for(var i=0;i<divs.length-1;i++){
    if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){
      var header=divs[i];
      var section=divs[i+1];
      var button=header.firstChild;
      if (button!='IMG'){
        divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild);
        button=document.createElement('img');
        divs[i].insertBefore(button,divs[i].firstChild);
      }
      header.style.cursor='pointer';
      header.onclick=changeDisplayState;
      header.id='dynheader'+sectionCounter;
      button.src='closed.gif';
      section.id='dynsection'+sectionCounter;
      section.style.display='none';
      section.style.marginLeft='14px';
      sectionCounter++;
    }
  }
}
window.onload = initDynSections;
-->
</script>
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="modules.html"><span>Modules</span></a></li>
    <li><a href="classes.html"><span>Data&nbsp;Structures</span></a></li>
    <li><a href="files.html"><span>Files</span></a></li>
    <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
  </ul>
</div>
<h1>Analog Inputs<br>
<small>
[<a class="el" href="group___controller.html">Controller</a>]</small>
</h1>The AnalogIn subsystem converts 0-3.3V signals to 10-bit digital values.  
<a href="#_details">More...</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___analog_in.html#ga3ae1add8529d6e1882b6c7d5b376b94">AnalogIn_SetActive</a> (int index, int state)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Sets whether the specified channel is active.  <a href="#ga3ae1add8529d6e1882b6c7d5b376b94"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___analog_in.html#gdb62eecf34834f2b57e722864581ace7">AnalogIn_GetActive</a> (int index)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Returns the active state of a channel.  <a href="#gdb62eecf34834f2b57e722864581ace7"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___analog_in.html#g66a6bd10fbb5fc80f32994b756cf0412">AnalogIn_GetValue</a> (int index)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Read the value of an analog input.  <a href="#g66a6bd10fbb5fc80f32994b756cf0412"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___analog_in.html#geee076abd9c478c3817552fdd586852d">AnalogIn_GetValueMulti</a> (int mask, int values[])</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Read the value of several of the analog inputs.  <a href="#geee076abd9c478c3817552fdd586852d"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___analog_in.html#g41030fda39d69b15cd29ac95d73fd932">AnalogIn_GetValueWait</a> (int index)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Read the value of an analog input without the use of any OS services.  <a href="#g41030fda39d69b15cd29ac95d73fd932"></a><br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
The AnalogIn subsystem converts 0-3.3V signals to 10-bit digital values. 
<p>
The analog to digital converters read incoming signals from 0 - 3.3V. They are rated as 5V tolerant, and indeed can momentarily withstand higher voltages, but will not return meaningful values for anything above 3.3V.<br>
<p>
Converting the 0 - 1023 reading of the AnalogIn channel into a voltage is performed as follows: <div class="fragment"><pre class="fragment">v = 3.3 * ( a / 1023.0 ) </pre></div> where a is the AnalogIn value<p>
This is of course a floating point operation (slowish) using a division (slowish). Fixed point versions may be more suitable for some applications. Where reduced accuracy is acceptable, the following can be used to get the input as a percentage of 3.3V: <div class="fragment"><pre class="fragment">p = ( 100 * a ) / 1023 </pre></div><p>
Initializing the controller's AnalogIn system is pretty involved (see AnalogIn_Init() in AnalogIn-&gt;c). There are a lot of different options - different converter speeds, DMA access, etc. We've chosen something pretty simple here. More ambitious users may wish to alter the implementation.<p>
<dl compact><dt><b><a class="el" href="todo.html#_todo000001">Todo:</a></b></dt><dd>Provide multi-channel conversion routines</dd></dl>
<hr><h2>Function Documentation</h2>
<a class="anchor" name="gdb62eecf34834f2b57e722864581ace7"></a><!-- doxytag: member="analogin.c::AnalogIn_GetActive" ref="gdb62eecf34834f2b57e722864581ace7" args="(int index)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int AnalogIn_GetActive           </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>index</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Returns the active state of a channel. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>index</em>&nbsp;</td><td>An integer specifying the ANALOGIN channel (0 - 7). </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>State - 1/non-zero (active) or 0 (inactive).</dd></dl>
<dl class="user" compact><dt><b>Example</b></dt><dd><div class="fragment"><pre class="fragment">  <span class="keywordtype">int</span> active = <a class="code" href="group___analog_in.html#gdb62eecf34834f2b57e722864581ace7" title="Returns the active state of a channel.">AnalogIn_GetActive</a>( 0 ) <span class="comment">// check whether analogin 0 is active</span>
</pre></div> </dd></dl>

<p>Definition at line <a class="el" href="analogin_8c-source.html#l00140">140</a> of file <a class="el" href="analogin_8c-source.html">analogin.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="g66a6bd10fbb5fc80f32994b756cf0412"></a><!-- doxytag: member="analogin.c::AnalogIn_GetValue" ref="g66a6bd10fbb5fc80f32994b756cf0412" args="(int index)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int AnalogIn_GetValue           </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>index</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Read the value of an analog input. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>index</em>&nbsp;</td><td>An integer specifying which input (0-7). </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>The value as an integer (0 - 1023).</dd></dl>
<dl class="user" compact><dt><b>Example</b></dt><dd><div class="fragment"><pre class="fragment">  <span class="keywordtype">int</span> analogin1 = <a class="code" href="group___analog_in.html#g66a6bd10fbb5fc80f32994b756cf0412" title="Read the value of an analog input.">AnalogIn_GetValue</a>( 1 );
</pre></div> </dd></dl>

<p>Definition at line <a class="el" href="analogin_8c-source.html#l00160">160</a> of file <a class="el" href="analogin_8c-source.html">analogin.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="geee076abd9c478c3817552fdd586852d"></a><!-- doxytag: member="analogin.c::AnalogIn_GetValueMulti" ref="geee076abd9c478c3817552fdd586852d" args="(int mask, int values[])" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int AnalogIn_GetValueMulti           </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>mask</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>values</em>[]</td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Read the value of several of the analog inputs. 
<p>
Due to the current ISR handling, this isn't too much quicker than making calls to each of the channels individually. <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>mask</em>&nbsp;</td><td>A bit mask specifying which channels to read. </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>values</em>&nbsp;</td><td>A pointer to an int array to be filled with the values. </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>0 on success, otherwise non-zero.</dd></dl>
<dl class="user" compact><dt><b>Example</b></dt><dd><div class="fragment"><pre class="fragment">  <span class="keywordtype">int</span> mask = 0xFF;
  <span class="keywordtype">int</span> samples[8];
  <a class="code" href="group___analog_in.html#geee076abd9c478c3817552fdd586852d" title="Read the value of several of the analog inputs.">AnalogIn_GetValueMulti</a>( mask, samples ); <span class="comment">// now samples is filled with all the analogin values</span>
</pre></div> </dd></dl>

<p>Definition at line <a class="el" href="analogin_8c-source.html#l00214">214</a> of file <a class="el" href="analogin_8c-source.html">analogin.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="g41030fda39d69b15cd29ac95d73fd932"></a><!-- doxytag: member="analogin.c::AnalogIn_GetValueWait" ref="g41030fda39d69b15cd29ac95d73fd932" args="(int index)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int AnalogIn_GetValueWait           </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>index</em>          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Read the value of an analog input without the use of any OS services. 
<p>
Note that this is not thread safe and shouldn't be used if another part of the code might be using it or the thread safe versions. <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>index</em>&nbsp;</td><td>An integer specifying which input (0-7). </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>The value as an integer (0 - 1023).</dd></dl>
<dl class="user" compact><dt><b>Example</b></dt><dd><div class="fragment"><pre class="fragment">  <span class="keywordtype">int</span> analogin1 = <a class="code" href="group___analog_in.html#g41030fda39d69b15cd29ac95d73fd932" title="Read the value of an analog input without the use of any OS services.">AnalogIn_GetValueWait</a>( 1 );
</pre></div> </dd></dl>

<p>Definition at line <a class="el" href="analogin_8c-source.html#l00272">272</a> of file <a class="el" href="analogin_8c-source.html">analogin.c</a>.</p>

</div>
</div><p>
<a class="anchor" name="ga3ae1add8529d6e1882b6c7d5b376b94"></a><!-- doxytag: member="analogin.c::AnalogIn_SetActive" ref="ga3ae1add8529d6e1882b6c7d5b376b94" args="(int index, int state)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int AnalogIn_SetActive           </td>
          <td>(</td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>index</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">int&nbsp;</td>
          <td class="paramname"> <em>state</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td width="100%"></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Sets whether the specified channel is active. 
<p>
This initializes the AnalogIn system and gets a lock on its IO lines. It only needs to be called once. <dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>index</em>&nbsp;</td><td>An integer specifying the channel (0 - 7). </td></tr>
    <tr><td valign="top"></td><td valign="top"><em>state</em>&nbsp;</td><td>An integer specifying the active state - 1 (active) or 0 (inactive). </td></tr>
  </table>
</dl>
<dl class="return" compact><dt><b>Returns:</b></dt><dd>Zero on success.</dd></dl>
<dl class="user" compact><dt><b>Example</b></dt><dd><div class="fragment"><pre class="fragment">  <span class="keywordflow">if</span>( <a class="code" href="group___analog_in.html#ga3ae1add8529d6e1882b6c7d5b376b94" title="Sets whether the specified channel is active.">AnalogIn_SetActive</a>( 0, 1 )  == <a class="code" href="group___error.html#gaa42bc036fbba18487ae9a15cd1f2f94" title="All&amp;#39;s well here.">CONTROLLER_OK</a> ) <span class="comment">// set analogin 0 to active</span>
    <span class="comment">// then continue processing</span>
  <span class="keywordflow">else</span>
    <span class="comment">// some error occurred</span>
</pre></div> </dd></dl>

<p>Definition at line <a class="el" href="analogin_8c-source.html#l00104">104</a> of file <a class="el" href="analogin_8c-source.html">analogin.c</a>.</p>

</div>
</div><p>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Make Controller Kit</title>
<style type="text/css">
<!--
.footer {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 9pt;
	color: #999999;
}
-->
</style>
</head>

<body>
<hr size="1">
<div>
  <p class="footer">The Make Controller Kit is an open source project maintained by <a href="http://www.makingthings.com">MakingThings</a>.<br />
    MakingThings code is released under the <a href="http://www.apache.org/licenses/LICENSE-2.0.html" target="_blank">Apache 2.0 license</a>.<br />
    Bug tracker, development wiki and status can be found at <a href="http://dev.makingthings.com">http://dev.makingthings.com</a>.<br />
		This document was last updated on 5 Dec 2007.
</p>
</div>
<!-- Google Analytics Code -->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-769030-1";
urchinTracker();
</script>
</body>
</html>
